<?php
/**
 * A simple description for this script
 *
 * PHP Version 5.2.0 or Upper version
 *
 * @package    Paylog
 * @author     Hidehito NOZAWA aka Suin <http://suin.asia>
 * @copyright  2010 Hidehito NOZAWA
 * @license    http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2
 *
 */

abstract class Paylog_Abstract_Controller
{
	protected $template = null;
	protected $output  = array();
	protected $session = array();
	protected $breadcrumbs = array();

	protected $config = array();

	public function __construct()
	{
		$this->config =& Paylog::$cms->getConfig();
		$this->output['config'] =& $this->config;
		$this->output['url']     = Paylog::$url;
		$this->output['dirname'] = Paylog::$dirname;
		$this->output['controller'] =& Paylog::$_controller;
		$this->output['action']     =& Paylog::$_action;

		if ( !isset($_SESSION[Paylog::$dirname]) )
		{
			$_SESSION[Paylog::$dirname] = array();
		}

		$this->session =& $_SESSION[Paylog::$dirname];

		$this->breadcrumbs[] = array(
			'name' => Paylog::msg("Top"),
			'url'  => Paylog::$url.'/',
		);
		$this->output['breadcrumbs'] =& $this->breadcrumbs;
	}

	public function main()
	{
	}

	protected function _view()
	{
		if ( !$this->template )
		{
			$this->template = 'db:'.Paylog::$dirname.'.'.Paylog::$_controller.'.'.Paylog::$_action.'.tpl';
		}

		$smarty = Paylog::$cms->getSmarty();
		$this->_escapeHtml($this->output);
		$smarty->assign('paylog', $this->output);
		$smarty->register_modifier('msg', 'Paylog::msg');
		$smarty->register_modifier('raw', 'Paylog_Class_Smarty::raw');
		$smarty->register_function('url', 'Paylog_Class_Smarty::url');
		$smarty->register_modifier('currency', 'Paylog_Class_Smarty::currency');
		$smarty->display($this->template);

		$this->_head($smarty);
	}

	protected function _escapeHtml(&$vars)
	{
		foreach ( $vars as $key => &$var )
		{
			if ( is_array($var) )
			{
				$this->_escapeHtml($var);
			}
			elseif ( !is_object($var) )
			{
				$var = Paylog::escapeHtml($var);
			}
		}
	}

	protected function _head($smarty)
	{
		Paylog::$cms->addHeader('<link rel="stylesheet" type="text/css" media="screen" href="'.Paylog::$url.'/public/css/stylesheet.css" />');
		Paylog::$cms->addHeader('<link rel="stylesheet" type="text/css" media="screen" href="'.Paylog::$url.'/public/css/custom.css" />');

		if ( class_exists('Paylog_Jquery', false) ) return;

		$head = $smarty->fetch('db:'.Paylog::$dirname.'.head.tpl');
		Paylog::$cms->addHeader($head);
	}
}

?>
